/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.erp.server.BPO;

/**
 *
 * @author Administrator
 */

import com.erp.client.DAO.UserBaseInf;
import com.erp.client.DAO.UserPasswordChange;
import com.erp.server.DAO.UserDao;
import java.sql.SQLException;

public class UserBPO {
private UserBaseInf userbaseinf;
private boolean  ups;


    // 添加一个用户
	public boolean addUser(UserBaseInf ub) throws SQLException {
		UserDao dao = new UserDao();
		try {
			return dao.addUser(ub);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
	}
	// 用户登录检查,如果为合法用户，则将用户信息保存在ub中
	public boolean check(UserBaseInf ub) {
		UserDao dao = new UserDao();
		try {
			setUb(dao.checkUser(ub));

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (getUb().getUserId()<1) {
			return false;
		} else {
			return true;
		}
	}



	// 检查是否存在该用户
	public boolean isHasUser(String username) throws SQLException {
		UserDao dao = new UserDao();
		return dao.isHasUser(username);
	}
      // 修改用户密码
	public boolean changePassword(UserPasswordChange ub){
		UserDao dao = new UserDao();
		try {
			setUps(dao.ChangePassword(ub));

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (isUps()) {
            return true;
		} else {
			return false;
		}
	}

    public UserBaseInf getUb() {
		return userbaseinf;
	}

	public void setUb(UserBaseInf ub) {
		this.userbaseinf = ub;
	}

    public boolean isUps() {
        return ups;
    }

    public void setUps(boolean ups) {
        this.ups = ups;
    }

}
